{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(8618, 36)\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "NDB_No               int64\n",
      "Shrt_Desc           object\n",
      "Water_(g)          float64\n",
      "Energ_Kcal           int64\n",
      "Protein_(g)        float64\n",
      "Lipid_Tot_(g)      float64\n",
      "Ash_(g)            float64\n",
      "Carbohydrt_(g)     float64\n",
      "Fiber_TD_(g)       float64\n",
      "Sugar_Tot_(g)      float64\n",
      "Calcium_(mg)       float64\n",
      "Iron_(mg)          float64\n",
      "Magnesium_(mg)     float64\n",
      "Phosphorus_(mg)    float64\n",
      "Potassium_(mg)     float64\n",
      "Sodium_(mg)        float64\n",
      "Zinc_(mg)          float64\n",
      "Copper_(mg)        float64\n",
      "Manganese_(mg)     float64\n",
      "Selenium_(mcg)     float64\n",
      "Vit_C_(mg)         float64\n",
      "Thiamin_(mg)       float64\n",
      "Riboflavin_(mg)    float64\n",
      "Niacin_(mg)        float64\n",
      "Vit_B6_(mg)        float64\n",
      "Vit_B12_(mcg)      float64\n",
      "Vit_A_IU           float64\n",
      "Vit_A_RAE          float64\n",
      "Vit_E_(mg)         float64\n",
      "Vit_D_mcg          float64\n",
      "Vit_D_IU           float64\n",
      "Vit_K_(mcg)        float64\n",
      "FA_Sat_(g)         float64\n",
      "FA_Mono_(g)        float64\n",
      "FA_Poly_(g)        float64\n",
      "Cholestrl_(mg)     float64\n",
      "dtype: object\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "food_info = pd.read_csv('food_info.csv')# 读取csv文件\n",
    "print(food_info.shape)# 查看维度信息\n",
    "print(type(food_info))# 查看类型\n",
    "print(food_info.dtypes)# 查看所有列的数据类型\n",
    "# print(help(pd.read_csv))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8618, 36)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# food_info.head()# 显示前5行\n",
    "# food_info.tail()# 显示后5行\n",
    "# food_info.columns# 显示列名\n",
    "food_info.shape# 查看dataframe维度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NDB_No</th>\n",
       "      <th>Shrt_Desc</th>\n",
       "      <th>Water_(g)</th>\n",
       "      <th>Energ_Kcal</th>\n",
       "      <th>Protein_(g)</th>\n",
       "      <th>Lipid_Tot_(g)</th>\n",
       "      <th>Ash_(g)</th>\n",
       "      <th>Carbohydrt_(g)</th>\n",
       "      <th>Fiber_TD_(g)</th>\n",
       "      <th>Sugar_Tot_(g)</th>\n",
       "      <th>...</th>\n",
       "      <th>Vit_A_IU</th>\n",
       "      <th>Vit_A_RAE</th>\n",
       "      <th>Vit_E_(mg)</th>\n",
       "      <th>Vit_D_mcg</th>\n",
       "      <th>Vit_D_IU</th>\n",
       "      <th>Vit_K_(mcg)</th>\n",
       "      <th>FA_Sat_(g)</th>\n",
       "      <th>FA_Mono_(g)</th>\n",
       "      <th>FA_Poly_(g)</th>\n",
       "      <th>Cholestrl_(mg)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1003</td>\n",
       "      <td>BUTTER OIL ANHYDROUS</td>\n",
       "      <td>0.24</td>\n",
       "      <td>876</td>\n",
       "      <td>0.28</td>\n",
       "      <td>99.48</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>...</td>\n",
       "      <td>3069.0</td>\n",
       "      <td>840.0</td>\n",
       "      <td>2.80</td>\n",
       "      <td>1.8</td>\n",
       "      <td>73.0</td>\n",
       "      <td>8.6</td>\n",
       "      <td>61.924</td>\n",
       "      <td>28.732</td>\n",
       "      <td>3.694</td>\n",
       "      <td>256.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1006</td>\n",
       "      <td>CHEESE BRIE</td>\n",
       "      <td>48.42</td>\n",
       "      <td>334</td>\n",
       "      <td>20.75</td>\n",
       "      <td>27.68</td>\n",
       "      <td>2.70</td>\n",
       "      <td>0.45</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.45</td>\n",
       "      <td>...</td>\n",
       "      <td>592.0</td>\n",
       "      <td>174.0</td>\n",
       "      <td>0.24</td>\n",
       "      <td>0.5</td>\n",
       "      <td>20.0</td>\n",
       "      <td>2.3</td>\n",
       "      <td>17.410</td>\n",
       "      <td>8.013</td>\n",
       "      <td>0.826</td>\n",
       "      <td>100.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1011</td>\n",
       "      <td>CHEESE COLBY</td>\n",
       "      <td>38.20</td>\n",
       "      <td>394</td>\n",
       "      <td>23.76</td>\n",
       "      <td>32.11</td>\n",
       "      <td>3.36</td>\n",
       "      <td>2.57</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.52</td>\n",
       "      <td>...</td>\n",
       "      <td>994.0</td>\n",
       "      <td>264.0</td>\n",
       "      <td>0.28</td>\n",
       "      <td>0.6</td>\n",
       "      <td>24.0</td>\n",
       "      <td>2.7</td>\n",
       "      <td>20.218</td>\n",
       "      <td>9.280</td>\n",
       "      <td>0.953</td>\n",
       "      <td>95.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3 rows × 36 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    NDB_No             Shrt_Desc  Water_(g)  Energ_Kcal  Protein_(g)  \\\n",
       "2     1003  BUTTER OIL ANHYDROUS       0.24         876         0.28   \n",
       "5     1006           CHEESE BRIE      48.42         334        20.75   \n",
       "10    1011          CHEESE COLBY      38.20         394        23.76   \n",
       "\n",
       "    Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  Fiber_TD_(g)  Sugar_Tot_(g)  \\\n",
       "2           99.48     0.00            0.00           0.0           0.00   \n",
       "5           27.68     2.70            0.45           0.0           0.45   \n",
       "10          32.11     3.36            2.57           0.0           0.52   \n",
       "\n",
       "         ...        Vit_A_IU  Vit_A_RAE  Vit_E_(mg)  Vit_D_mcg  Vit_D_IU  \\\n",
       "2        ...          3069.0      840.0        2.80        1.8      73.0   \n",
       "5        ...           592.0      174.0        0.24        0.5      20.0   \n",
       "10       ...           994.0      264.0        0.28        0.6      24.0   \n",
       "\n",
       "    Vit_K_(mcg)  FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  Cholestrl_(mg)  \n",
       "2           8.6      61.924       28.732        3.694           256.0  \n",
       "5           2.3      17.410        8.013        0.826           100.0  \n",
       "10          2.7      20.218        9.280        0.953            95.0  \n",
       "\n",
       "[3 rows x 36 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# food_info.loc[0]# 切片，查看第1行\n",
    "# food_info.loc[[2, 5, 10]]# 查看指定行数据，注意中间是个list[2, 5, 10]\n",
    "food_info.loc[:5,:]# 前面行，后面列，这里是前6行，所有列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>NDB_No</th>\n",
       "      <th>Shrt_Desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1001</td>\n",
       "      <td>BUTTER WITH SALT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1002</td>\n",
       "      <td>BUTTER WHIPPED WITH SALT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1003</td>\n",
       "      <td>BUTTER OIL ANHYDROUS</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1004</td>\n",
       "      <td>CHEESE BLUE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1005</td>\n",
       "      <td>CHEESE BRICK</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1006</td>\n",
       "      <td>CHEESE BRIE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1007</td>\n",
       "      <td>CHEESE CAMEMBERT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1008</td>\n",
       "      <td>CHEESE CARAWAY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1009</td>\n",
       "      <td>CHEESE CHEDDAR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1010</td>\n",
       "      <td>CHEESE CHESHIRE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1011</td>\n",
       "      <td>CHEESE COLBY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1012</td>\n",
       "      <td>CHEESE COTTAGE CRMD LRG OR SML CURD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>1013</td>\n",
       "      <td>CHEESE COTTAGE CRMD W/FRUIT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>1014</td>\n",
       "      <td>CHEESE COTTAGE NONFAT UNCRMD DRY LRG OR SML CURD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>1015</td>\n",
       "      <td>CHEESE COTTAGE LOWFAT 2% MILKFAT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1016</td>\n",
       "      <td>CHEESE COTTAGE LOWFAT 1% MILKFAT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>1017</td>\n",
       "      <td>CHEESE CREAM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>1018</td>\n",
       "      <td>CHEESE EDAM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>1019</td>\n",
       "      <td>CHEESE FETA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>1020</td>\n",
       "      <td>CHEESE FONTINA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>1021</td>\n",
       "      <td>CHEESE GJETOST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>1022</td>\n",
       "      <td>CHEESE GOUDA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>1023</td>\n",
       "      <td>CHEESE GRUYERE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>1024</td>\n",
       "      <td>CHEESE LIMBURGER</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>1025</td>\n",
       "      <td>CHEESE MONTEREY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>1026</td>\n",
       "      <td>CHEESE MOZZARELLA WHL MILK</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>1027</td>\n",
       "      <td>CHEESE MOZZARELLA WHL MILK LO MOIST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>1028</td>\n",
       "      <td>CHEESE MOZZARELLA PART SKIM MILK</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>1029</td>\n",
       "      <td>CHEESE MOZZARELLA LO MOIST PART-SKIM</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>1030</td>\n",
       "      <td>CHEESE MUENSTER</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8588</th>\n",
       "      <td>43544</td>\n",
       "      <td>BABYFOOD CRL RICE W/ PEARS &amp; APPL DRY INST</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8589</th>\n",
       "      <td>43546</td>\n",
       "      <td>BABYFOOD BANANA NO TAPIOCA STR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8590</th>\n",
       "      <td>43550</td>\n",
       "      <td>BABYFOOD BANANA APPL DSSRT STR</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8591</th>\n",
       "      <td>43566</td>\n",
       "      <td>SNACKS TORTILLA CHIPS LT (BAKED W/ LESS OIL)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8592</th>\n",
       "      <td>43570</td>\n",
       "      <td>CEREALS RTE POST HONEY BUNCHES OF OATS HONEY RSTD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8593</th>\n",
       "      <td>43572</td>\n",
       "      <td>POPCORN MICROWAVE LOFAT&amp;NA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8594</th>\n",
       "      <td>43585</td>\n",
       "      <td>BABYFOOD FRUIT SUPREME DSSRT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8595</th>\n",
       "      <td>43589</td>\n",
       "      <td>CHEESE SWISS LOW FAT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8596</th>\n",
       "      <td>43595</td>\n",
       "      <td>BREAKFAST BAR CORN FLAKE CRUST W/FRUIT</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8597</th>\n",
       "      <td>43597</td>\n",
       "      <td>CHEESE MOZZARELLA LO NA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8598</th>\n",
       "      <td>43598</td>\n",
       "      <td>MAYONNAISE DRSNG NO CHOL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8599</th>\n",
       "      <td>44005</td>\n",
       "      <td>OIL CORN PEANUT AND OLIVE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8600</th>\n",
       "      <td>44018</td>\n",
       "      <td>SWEETENERS TABLETOP FRUCTOSE LIQ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8601</th>\n",
       "      <td>44048</td>\n",
       "      <td>CHEESE FOOD IMITATION</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8602</th>\n",
       "      <td>44055</td>\n",
       "      <td>CELERY FLAKES DRIED</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8603</th>\n",
       "      <td>44061</td>\n",
       "      <td>PUDDINGS CHOC FLAVOR LO CAL INST DRY MIX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8604</th>\n",
       "      <td>44074</td>\n",
       "      <td>BABYFOOD GRAPE JUC NO SUGAR CND</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8605</th>\n",
       "      <td>44110</td>\n",
       "      <td>JELLIES RED SUGAR HOME PRESERVED</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8606</th>\n",
       "      <td>44158</td>\n",
       "      <td>PIE FILLINGS BLUEBERRY CND</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8607</th>\n",
       "      <td>44203</td>\n",
       "      <td>COCKTAIL MIX NON-ALCOHOLIC CONCD FRZ</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8608</th>\n",
       "      <td>44258</td>\n",
       "      <td>PUDDINGS CHOC FLAVOR LO CAL REG DRY MIX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8609</th>\n",
       "      <td>44259</td>\n",
       "      <td>PUDDINGS ALL FLAVORS XCPT CHOC LO CAL REG DRY MIX</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8610</th>\n",
       "      <td>44260</td>\n",
       "      <td>PUDDINGS ALL FLAVORS XCPT CHOC LO CAL INST DRY...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8611</th>\n",
       "      <td>48052</td>\n",
       "      <td>VITAL WHEAT GLUTEN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8612</th>\n",
       "      <td>80200</td>\n",
       "      <td>FROG LEGS RAW</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8613</th>\n",
       "      <td>83110</td>\n",
       "      <td>MACKEREL SALTED</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8614</th>\n",
       "      <td>90240</td>\n",
       "      <td>SCALLOP (BAY&amp;SEA) CKD STMD</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8615</th>\n",
       "      <td>90480</td>\n",
       "      <td>SYRUP CANE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8616</th>\n",
       "      <td>90560</td>\n",
       "      <td>SNAIL RAW</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8617</th>\n",
       "      <td>93600</td>\n",
       "      <td>TURTLE GREEN RAW</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8618 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      NDB_No                                          Shrt_Desc\n",
       "0       1001                                   BUTTER WITH SALT\n",
       "1       1002                           BUTTER WHIPPED WITH SALT\n",
       "2       1003                               BUTTER OIL ANHYDROUS\n",
       "3       1004                                        CHEESE BLUE\n",
       "4       1005                                       CHEESE BRICK\n",
       "5       1006                                        CHEESE BRIE\n",
       "6       1007                                   CHEESE CAMEMBERT\n",
       "7       1008                                     CHEESE CARAWAY\n",
       "8       1009                                     CHEESE CHEDDAR\n",
       "9       1010                                    CHEESE CHESHIRE\n",
       "10      1011                                       CHEESE COLBY\n",
       "11      1012                CHEESE COTTAGE CRMD LRG OR SML CURD\n",
       "12      1013                        CHEESE COTTAGE CRMD W/FRUIT\n",
       "13      1014   CHEESE COTTAGE NONFAT UNCRMD DRY LRG OR SML CURD\n",
       "14      1015                   CHEESE COTTAGE LOWFAT 2% MILKFAT\n",
       "15      1016                   CHEESE COTTAGE LOWFAT 1% MILKFAT\n",
       "16      1017                                       CHEESE CREAM\n",
       "17      1018                                        CHEESE EDAM\n",
       "18      1019                                        CHEESE FETA\n",
       "19      1020                                     CHEESE FONTINA\n",
       "20      1021                                     CHEESE GJETOST\n",
       "21      1022                                       CHEESE GOUDA\n",
       "22      1023                                     CHEESE GRUYERE\n",
       "23      1024                                   CHEESE LIMBURGER\n",
       "24      1025                                    CHEESE MONTEREY\n",
       "25      1026                         CHEESE MOZZARELLA WHL MILK\n",
       "26      1027                CHEESE MOZZARELLA WHL MILK LO MOIST\n",
       "27      1028                   CHEESE MOZZARELLA PART SKIM MILK\n",
       "28      1029               CHEESE MOZZARELLA LO MOIST PART-SKIM\n",
       "29      1030                                    CHEESE MUENSTER\n",
       "...      ...                                                ...\n",
       "8588   43544         BABYFOOD CRL RICE W/ PEARS & APPL DRY INST\n",
       "8589   43546                     BABYFOOD BANANA NO TAPIOCA STR\n",
       "8590   43550                     BABYFOOD BANANA APPL DSSRT STR\n",
       "8591   43566       SNACKS TORTILLA CHIPS LT (BAKED W/ LESS OIL)\n",
       "8592   43570  CEREALS RTE POST HONEY BUNCHES OF OATS HONEY RSTD\n",
       "8593   43572                         POPCORN MICROWAVE LOFAT&NA\n",
       "8594   43585                       BABYFOOD FRUIT SUPREME DSSRT\n",
       "8595   43589                               CHEESE SWISS LOW FAT\n",
       "8596   43595             BREAKFAST BAR CORN FLAKE CRUST W/FRUIT\n",
       "8597   43597                            CHEESE MOZZARELLA LO NA\n",
       "8598   43598                           MAYONNAISE DRSNG NO CHOL\n",
       "8599   44005                          OIL CORN PEANUT AND OLIVE\n",
       "8600   44018                   SWEETENERS TABLETOP FRUCTOSE LIQ\n",
       "8601   44048                              CHEESE FOOD IMITATION\n",
       "8602   44055                                CELERY FLAKES DRIED\n",
       "8603   44061           PUDDINGS CHOC FLAVOR LO CAL INST DRY MIX\n",
       "8604   44074                    BABYFOOD GRAPE JUC NO SUGAR CND\n",
       "8605   44110                   JELLIES RED SUGAR HOME PRESERVED\n",
       "8606   44158                         PIE FILLINGS BLUEBERRY CND\n",
       "8607   44203               COCKTAIL MIX NON-ALCOHOLIC CONCD FRZ\n",
       "8608   44258            PUDDINGS CHOC FLAVOR LO CAL REG DRY MIX\n",
       "8609   44259  PUDDINGS ALL FLAVORS XCPT CHOC LO CAL REG DRY MIX\n",
       "8610   44260  PUDDINGS ALL FLAVORS XCPT CHOC LO CAL INST DRY...\n",
       "8611   48052                                 VITAL WHEAT GLUTEN\n",
       "8612   80200                                      FROG LEGS RAW\n",
       "8613   83110                                    MACKEREL SALTED\n",
       "8614   90240                         SCALLOP (BAY&SEA) CKD STMD\n",
       "8615   90480                                         SYRUP CANE\n",
       "8616   90560                                          SNAIL RAW\n",
       "8617   93600                                   TURTLE GREEN RAW\n",
       "\n",
       "[8618 rows x 2 columns]"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# food_info['NDB_No']# 根据列名查看数据\n",
    "food_info[['NDB_No','Shrt_Desc']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Water_(g)</th>\n",
       "      <th>Protein_(g)</th>\n",
       "      <th>Lipid_Tot_(g)</th>\n",
       "      <th>Ash_(g)</th>\n",
       "      <th>Carbohydrt_(g)</th>\n",
       "      <th>Fiber_TD_(g)</th>\n",
       "      <th>Sugar_Tot_(g)</th>\n",
       "      <th>FA_Sat_(g)</th>\n",
       "      <th>FA_Mono_(g)</th>\n",
       "      <th>FA_Poly_(g)</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>15.87</td>\n",
       "      <td>0.85</td>\n",
       "      <td>81.11</td>\n",
       "      <td>2.11</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.06</td>\n",
       "      <td>51.368</td>\n",
       "      <td>21.021</td>\n",
       "      <td>3.043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>15.87</td>\n",
       "      <td>0.85</td>\n",
       "      <td>81.11</td>\n",
       "      <td>2.11</td>\n",
       "      <td>0.06</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.06</td>\n",
       "      <td>50.489</td>\n",
       "      <td>23.426</td>\n",
       "      <td>3.012</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.24</td>\n",
       "      <td>0.28</td>\n",
       "      <td>99.48</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>61.924</td>\n",
       "      <td>28.732</td>\n",
       "      <td>3.694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>42.41</td>\n",
       "      <td>21.40</td>\n",
       "      <td>28.74</td>\n",
       "      <td>5.11</td>\n",
       "      <td>2.34</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.50</td>\n",
       "      <td>18.669</td>\n",
       "      <td>7.778</td>\n",
       "      <td>0.800</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>41.11</td>\n",
       "      <td>23.24</td>\n",
       "      <td>29.68</td>\n",
       "      <td>3.18</td>\n",
       "      <td>2.79</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.51</td>\n",
       "      <td>18.764</td>\n",
       "      <td>8.598</td>\n",
       "      <td>0.784</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Water_(g)  Protein_(g)  Lipid_Tot_(g)  Ash_(g)  Carbohydrt_(g)  \\\n",
       "0      15.87         0.85          81.11     2.11            0.06   \n",
       "1      15.87         0.85          81.11     2.11            0.06   \n",
       "2       0.24         0.28          99.48     0.00            0.00   \n",
       "3      42.41        21.40          28.74     5.11            2.34   \n",
       "4      41.11        23.24          29.68     3.18            2.79   \n",
       "\n",
       "   Fiber_TD_(g)  Sugar_Tot_(g)  FA_Sat_(g)  FA_Mono_(g)  FA_Poly_(g)  \n",
       "0           0.0           0.06      51.368       21.021        3.043  \n",
       "1           0.0           0.06      50.489       23.426        3.012  \n",
       "2           0.0           0.00      61.924       28.732        3.694  \n",
       "3           0.0           0.50      18.669        7.778        0.800  \n",
       "4           0.0           0.51      18.764        8.598        0.784  "
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 根据结尾为'(g)'列查询\n",
    "col_names = food_info.columns.tolist()\n",
    "gram_columns = []\n",
    "for c in col_names:\n",
    "    if c.endswith(\"(g)\"):\n",
    "        gram_columns.append(c)\n",
    "gram_df = food_info[gram_columns]\n",
    "gram_df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(8618, 36)"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# print(food_info['Iron_(mg)'])\n",
    "div_1000 = food_info['Iron_(mg)'] / 1000\n",
    "div_1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(8618, 36)\n",
      "(8618, 37)\n"
     ]
    }
   ],
   "source": [
    "water_energy = food_info['Water_(g)'] * food_info['Energ_Kcal']\n",
    "iron_grams = food_info['Iron_(mg)'] / 1000\n",
    "print(food_info.shape)\n",
    "food_info['Iron_(g)'] = iron_grams# 新建列并赋值\n",
    "print(food_info.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [],
   "source": [
    "max_calories = food_info['Energ_Kcal'].max()# 最大值\n",
    "min_calories = food_info['Energ_Kcal'].min()# 最小值\n",
    "mean_calories = food_info['Energ_Kcal'].mean()# 平均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "276     38758.0\n",
       "5814    27360.0\n",
       "6192    26050.0\n",
       "1242    26000.0\n",
       "1245    24000.0\n",
       "1243    24000.0\n",
       "1244    23875.0\n",
       "292     17000.0\n",
       "1254    11588.0\n",
       "5811    10600.0\n",
       "8575     9690.0\n",
       "291      8068.0\n",
       "1249     8031.0\n",
       "5812     7893.0\n",
       "1292     7851.0\n",
       "293      7203.0\n",
       "4472     7027.0\n",
       "4836     6820.0\n",
       "1261     6580.0\n",
       "3747     6008.0\n",
       "1266     5730.0\n",
       "4835     5586.0\n",
       "4834     5493.0\n",
       "1263     5356.0\n",
       "1553     5203.0\n",
       "1552     5053.0\n",
       "1251     4957.0\n",
       "1257     4843.0\n",
       "294      4616.0\n",
       "8613     4450.0\n",
       "         ...   \n",
       "8153        NaN\n",
       "8155        NaN\n",
       "8156        NaN\n",
       "8157        NaN\n",
       "8158        NaN\n",
       "8159        NaN\n",
       "8160        NaN\n",
       "8161        NaN\n",
       "8163        NaN\n",
       "8164        NaN\n",
       "8165        NaN\n",
       "8167        NaN\n",
       "8169        NaN\n",
       "8170        NaN\n",
       "8172        NaN\n",
       "8173        NaN\n",
       "8174        NaN\n",
       "8175        NaN\n",
       "8176        NaN\n",
       "8177        NaN\n",
       "8178        NaN\n",
       "8179        NaN\n",
       "8180        NaN\n",
       "8181        NaN\n",
       "8183        NaN\n",
       "8184        NaN\n",
       "8185        NaN\n",
       "8195        NaN\n",
       "8251        NaN\n",
       "8267        NaN\n",
       "Name: Sodium_(mg), Length: 8618, dtype: float64"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "food_info.sort_values(\"Sodium_(mg)\", inplace=True, ascending=False)# 排序 inplace=True 替换原dataframe，ascending=False降序，缺失值NaN任何情况放在最后\n",
    "food_info[\"Sodium_(mg)\"]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
